package com.volcreate.inn.vo;


import com.volcreate.inn.po.Blog;
import com.volcreate.inn.po.Tag;
import com.volcreate.inn.po.Type;
import com.volcreate.inn.po.User;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author zxc
 * @version 0.0.2
 * @date 2020/8/24
 */
@Data
public class BlogVO extends Blog implements Serializable {

//    private Long id;
//
//    private String title;
//    private String firstPicture;
//    private String content;
//    private String description;
//    private String flag;
//
//    private Boolean recommendable;
//    private Boolean published;
//    private Boolean appreciative;
//    private Boolean commentable;
//    private Boolean shareStatement;
//
//    private Integer views;
//
//    private Date gmtCreate;
//    private Date gmtModified;

    private User user;
    private Type type;
    private List<Tag> tags;
    private String tagIds;

    public void init() {
        this.tagIds = tagsToIds(this.getTags());
    }

    private String tagsToIds(List<Tag> tags) {
        if (!tags.isEmpty()) {
            StringBuffer ids = new StringBuffer();
            boolean flag = false;
            for (Tag tag : tags) {
                if (flag) {
                    ids.append(",");
                } else {
                    flag = true;
                }
                ids.append(tag.getId());
            }
            return ids.toString();
        } else {
            return tagIds;
        }
    }


}
